<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>手机充电效果</title>
  <style>
    html,
    body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
      display: flex;
      background-color: #e4e4e4;
    }

    .container {
      position: relative;
      width: 140px;
      margin: auto;
    }

    .battery {
      height: 220px;
      box-sizing: border-box;
      border-radius: 15px 15px 5px 5px;
      filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.22));
      background: #fff;
      z-index: 1;
    }

    /*电池的正极*/
    .battery::before {
      content: "";
      position: absolute;
      width: 26px;
      height: 10px;
      left: 50%;
      top: 0;
      transform: translate(-50%, -10px);
      border-radius: 5px 5px 0 0;
      background: rgba(240, 240, 240, .88);
    }

    .battery::after {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      /*距离顶部的距离越来越小，模拟充电效果*/
      top: 90%;
      background: linear-gradient(to bottom, #7abcff 0%, #00bcd4 44%, #2196f3 100%);
      border-radius: 0 0 5px 5px;
      box-shadow: 0 14px 28px rgba(33, 150, 243, 0), 0 10px 10px rgba(9, 188, 215, .88);
      animation: charging 6s linear infinite;
      /* 这个滤镜会改变 linear-gradient的颜色*/
      /* 使用 filter: hue-rotate() 对渐变色彩进行色彩过渡变换动画
我们无法对一个渐变色直接进行 animation ，这里通过滤镜对色相进行调整，从而实现了渐变色的变换动画。 */
      filter: hue-rotate(90deg);
    }

    @keyframes charging {
      50% {
        box-shadow: 0 14px 28px rgba(0, 150, 136, 0.83), 0px 4px 10px rgba(9, 188, 215, 0.4);

      }

      95% {
        top: 5%;
        border-radius: 0 0 5px 5px;
        filter: hue-rotate(0deg);
        box-shadow: 0 14px 28px rgba(4, 188, 213, .2), 0 10px 10px rgba(9, 188, 215, 0.08);
      }

      100% {
        top: 0%;
        filter: hue-rotate(0deg);
        border-radius: 15px 15px 5px 5px;
        box-shadow: 0 14px 28px rgba(4, 188, 213, 0), 0 10px 10px rgba(9, 188, 215, 0.4);
      }
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="battery"></div>
  </div>
</body>

</html>